
from django.contrib import admin # admin是一个应用，django提供的后台管理站点
from django.conf.urls import re_path
from rest_framework.routers import DefaultRouter,SimpleRouter
from BookTest.views import *

from rest_framework.documentation import include_docs_urls


# 路由列表
urlpatterns = [
    re_path(r'^admin/', admin.site.urls),
    re_path(r'^docs/', include_docs_urls(title="图书管理接口文档中心！"))

    # PATCH + /books/<pk>/ = self.read
    # re_path(r'^books/(?P<pk>\d+)/read/$', BooksViewSet.as_view({"patch": "read"})),
    #
    # re_path(r'^books/$', BooksViewSet.as_view({"get": "list", "post": "create"})),
    # re_path(r'^books/(?P<pk>\d+)/$', BooksViewSet.as_view({
    #     "get": "retrieve",
    #     "put": "update",
    #     "patch": "partial_update",
    #     "delete": "destroy"
    # })),
]

# 使用DRF的路由实现自动添加映射
# 1、构建路由对象
router = SimpleRouter()
# router = DefaultRouter()
# 2、自动生成映射关系（注册视图集）
# /books/ + GET = self.list
# /books/ + POST = self.create
# /books/(?P<pk>\d+)/ + GET = self.retrieve
# /books/(?P<pk>\d+)/ + PUT = self.update
# /books/(?P<pk>\d+)/ + PATCH = self.partial_update
# /books/(?P<pk>\d+)/ + DELETE = self.destroy
router.register(prefix='books', viewset=BooksViewSet, base_name='books')
router.register(prefix='heros', viewset=HerosViewSet, base_name='heros')
# 3、添加到路由映射列表里
# router.urls = [re_path("books/"...), re_path("books/(?P<pk>\d+"...)]
# urlpatterns.extend(router.urls)
urlpatterns += router.urls





